<template>
  <PageWrapper title="上传组件示例">
    <Alert message="基础示例" />
    <BasicUpload
      :maxSize="20"
      :maxNumber="10"
      v-model:value="fileList"
      @change="handleChange"
      :api="uploadApi"
      class="my-5"
      :accept="['image/*']"
    />

    <Alert message="嵌入表单,加入表单校验" />

    <BasicForm @register="register" class="my-5" />
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { BasicUpload } from '@mxpio/components/src/Upload';
  import { useMessage } from '@mxpio/hooks/src/web/useMessage';
  import { BasicForm, FormSchema, useForm } from '@mxpio/components/src/Form';
  import { PageWrapper } from '@mxpio/components/src/Page';
  import { Alert } from 'ant-design-vue';
  import { uploadApi } from '@mxpio/api/src/sys/upload';
  import { ref } from 'vue';

  const schemas: FormSchema[] = [
    {
      field: 'field1',
      component: 'Upload',
      label: '字段1',
      colProps: {
        span: 8,
      },
      rules: [{ required: true, message: '请选择上传文件' }],
      componentProps: {
        api: uploadApi,
      },
    },
  ];
  const { createMessage } = useMessage();
  const [register] = useForm({
    labelWidth: 120,
    schemas,
    actionColOptions: {
      span: 16,
    },
  });
  const fileList: string[] = ref([
    '81a4cfbf-70ba-44b6-abc8-1a51078e87c4',
    '2c99562a-5c86-4cab-9531-22df02bff3a0',
  ]);
  function handleChange(list: string[]) {
    createMessage.info(`已上传文件${JSON.stringify(list)}`);
  }
</script>
